package com.movitech.mobile.cz.base.purchase.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.movitech.mobile.cz.base.common.license.LicenseUtil;
import com.movitech.mobile.cz.base.common.util.CommonConstants;
import com.movitech.mobile.cz.base.common.utils.IdGen;
import com.movitech.mobile.cz.base.purchase.entity.PSpRequiredDetail;
import com.movitech.mobile.cz.base.purchase.entity.ext.ExtPSpRequiredDetail;
import com.movitech.mobile.cz.base.purchase.entity.ext.SpRequiredDetailFindRequest;
import com.movitech.mobile.cz.base.purchase.mapper.PSpRequiredDetailMapper;
import com.movitech.mobile.cz.base.purchase.mapper.ext.ExtPSpRequiredDetailMapper;
import com.movitech.mobile.cz.base.purchase.service.PSpRequiredDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 战略采购需求-需求明细 服务实现类
 * </p>
 *
 * @author Movitech Mobile
 * @since 2018-03-15
 */
@Service
public class PSpRequiredDetailServiceImpl extends ServiceImpl<PSpRequiredDetailMapper, PSpRequiredDetail> implements PSpRequiredDetailService {

    @Autowired
    private ExtPSpRequiredDetailMapper extpSpRequiredDetailMapper;

    @Override
    public PSpRequiredDetail savePSpRequiredDetail(PSpRequiredDetail pSpRequiredDetail) {
        LicenseUtil.INSTANCE.validate();
        pSpRequiredDetail.setId(IdGen.uuid());
        insert(pSpRequiredDetail);
        return pSpRequiredDetail;
    }

    @Override
    public List<ExtPSpRequiredDetail> findRequiredDetail(SpRequiredDetailFindRequest requiredDetailFindRequest){
        return extpSpRequiredDetailMapper.findRequiredDetail(requiredDetailFindRequest);
    }

    @Override
    public boolean deleteByRequireId(String id) {
        LicenseUtil.INSTANCE.validate();
        PSpRequiredDetail where = new PSpRequiredDetail();
        where.setStrategicPurchaseRequiredId(id);
        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.setEntity(where);
        PSpRequiredDetail update = new PSpRequiredDetail();
        update.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
        return update(update,entityWrapper);
    }
}
